Page({
  /**
   * 页面的初始数据
   */
  data: {
    tipText: '',
    maxNum: 10,
    through: false,
    allData0: [5, 4, 3, 3, 0, 0],
    corpKey: '',
    jkJbxxSfxx: '',
    autoScore: '',
    autoName: '科创准入评分初评',
    subIshow: true,
    Company: '',
    allData: "",
    loading: true,
    headType: '1',
    optionList: [{
      title: '人才企业',
      children: [{
        title: '人才评定',
        key: 'rcpd',
        children: [{
          name: '国家级“领军人才”、“千人计划”创办的研发型企业',
          fraction: 5,
          check: false
        }, {
          name: '省双创等省市级领军人才创办的研发型企业',
          fraction: 4,
          check: false
        }, {
          name: '姑苏领军、园区领军人才创办的研发型企业',
          fraction: 3,
          check: false
        }, {
          name: '其他人才认定资质创办的研发型企业',
          fraction: 2,
          check: false
        }, {
          name: '不符合以上情况',
          fraction: 0,
          check: false
        }]
      }],
    }, {
      title: "资本市场",
      children: [{
        title: '上市情况',
        key: 'ssqk',
        children: [{
          name: '已上市（沪深主板、创业板、科创板、北交所）',
          fraction: 5,
          check: false
        }, {
          name: '提交IPO上市申请且审核正常（已申报时点为准）',
          fraction: 4,
          check: false
        }, {
          name: '申请人上市辅导阶段（已签署辅导协议）',
          fraction: 3,
          check: false
        }, {
          name: 'B轮融资（含）以上',
          fraction: 2,
          check: false
        }, {
          name: '天使轮、A、A+轮融资',
          fraction: 1,
          check: false
        }, {
          name: '不符合以上情况',
          fraction: 0,
          check: false
        }]
      },],
    }, {
      title: '成长性指标',
      children: [{
        title: '行业地位',
        key: 'hydw',
        children: [{
          name: '细分行业市场占有率前五',
          fraction: 5,
          check: false
        }, {
          name: '细分行业市场占有率前十',
          fraction: 3,
          check: false
        }, {
          name: '细分行业市场占有率前二十',
          fraction: 1,
          check: false
        }, {
          name: '不符合以上情况',
          fraction: 0,
          check: false
        }]
      }, {
        title: '研发管线（生物医药适用）（加分项）',
        key: 'yfgx',
        children: [{
          name: '研发管线不少于2条，且至少1条新药进入临床Ⅲ期',
          fraction: 5,
          check: false
        }, {
          name: '研发管线不少于2条，且至少1条新药进入临床Ⅱ期',
          fraction: 3,
          check: false
        }, {
          name: '研发管线不少于1条，且至少1条新药进入临床Ⅰ期',
          fraction: 2,
          check: false
        }, {
          name: '不符合以上情况',
          fraction: 0,
          check: false
        }]
      }, {
        title: '产品进度（半导体、新能源汽车、光伏适用）（加分项）',
        key: 'cpjd',
        children: [{
          name: '主要产品已获得细分行业前十客户订单',
          fraction: 5,
          check: false
        }, {
          name: '主要产品已通过细分行业前十客户测试',
          fraction: 3,
          check: false
        }, {
          name: '主要产品已完成设计或制造，包括芯片设计成功流片、设备或材料制造突破等',
          fraction: 2,
          check: false
        }, {
          name: '不符合以上情况',
          fraction: 0,
          check: false
        }]
      }],
    }],
    corpName: '',
    isPass: ''
  },
  goSub() {
    let dataList = this.data.optionList
    let obj = {}
    let total = 0
    for (let i in dataList) {
      for (let a in dataList[i].children) {
        obj[dataList[i].children[a].key] = 0
        for (let e in dataList[i].children[a].children) {
          if (dataList[i].children[a].children[e].check == true) {
            obj[dataList[i].children[a].key] = dataList[i].children[a].children[e].fraction
            total += dataList[i].children[a].children[e].fraction
          }
        }
      }
    }
    let newList = this.data.allData0
    if (this.data.autoScore == 0 && obj.cpjd == 0 && obj.hydw == 0 && obj.rcpd == 0 && obj.ssqk == 0 && obj.yfgx == 0) {
      newList = [0, 0, 0, 0, 0, 0, 0, 0, 0]
    } else {
      newList.push(obj.rcpd == 0 ? obj.rcpd + 2 : obj.rcpd, obj.ssqk == 0 ? obj.ssqk + 2 : obj.ssqk, obj.hydw == 0 ? obj.hydw + 2 : obj.hydw, obj.yfgx == 0 ? obj.yfgx + 2 : obj.yfgx, obj.cpjd == 0 ? obj.cpjd + 2 : obj.cpjd)
    }

    let autoScoreClone = this.data.autoScore

    this.setData({
      subIshow: false,
      allData0: newList,
      autoName: '科创准入评分终评',
      through: false,
    })
    let maxNum = Math.max.apply(null, newList)

    this.setData({
      autoScore: autoScoreClone + total,
      maxNum: maxNum,
      through: true
    })
  },
  goSub2() {
    let newList = this.data.allData0
    if (this.data.autoScore == 0) {
      newList = [0, 0, 0, 0, 0, 0, 0, 0, 0]
    } else {
      newList.push(2, 2, 2, 2, 2)
    }
    let maxNum = Math.max.apply(null, this.data.allData0)
    this.setData({
      maxNum: maxNum,
      subIshow: false,
      allData0: newList,
      autoName: '科创准入评分终评',
    })
  },
  optionCheck(data) {
    let item = data.currentTarget.dataset.item
    let itemfather = data.currentTarget.dataset.itemfather
    let dataList = this.data.optionList
    if (item.check == true) {
      for (let i in dataList) {
        for (let a in dataList[i].children) {
          for (let e in dataList[i].children[a].children)
            dataList[i].children[a].children[e].check = false
        }
      }
    } else {
      for (let i in dataList) {
        for (let a in dataList[i].children) {
          if (dataList[i].children[a].title == itemfather.title) {
            for (let e in dataList[i].children[a].children) {
              dataList[i].children[a].children[e].check = false
              if (dataList[i].children[a].children[e].name == item.name) {
                dataList[i].children[a].children[e].check = true
              }
            }
          }
        }
      }
    }
    this.setData({
      optionList: dataList
    })
  },
  headChange(data) {
    this.setData({
      headType: data.currentTarget.dataset.type
    })
  },
  getScore() {

    getApp()
      .globalData.request(
        "/map/getMsyhScoreInfo", {
        corpKey: this.data.corpKey,
      },
        "POST"
      )
      .then((rstObj) => {
        console.log(rstObj, '接口数据')
        if (rstObj.data == null) {
          this.setData({
            autoName: '',
            tipText: '暂无评分信息',
            through: false,
            loading: false,
            isPass: ''
          })
          return false
        }
        if (rstObj.data.isPass == '通过') {
          this.setData({
            through: true,
            allData0: [rstObj.data.kcScore + 2, rstObj.data.cwScore + 2, rstObj.data.hzScore + 2, rstObj.data.pfScore + 2],
            autoScore: rstObj.data.autoScore,
            isPass: '通过'
          })
        } else {
          this.setData({
            // tipText: '评分未通过',
            tipText: rstObj.data.autoScore,
            autoName: rstObj.data.isPass,
            through: false,
            isPass: rstObj.data.isPass
          })
        }
        let insertParmas = {
          corpKey: this.data.corpKey,
          corpName: this.data.corpName,
          isPass: this.data.isPass,
          userId: wx.getStorageSync('userInfo').userId,
          initScore: JSON.stringify(this.data.autoScore)
        }
        console.log(insertParmas, 'insertParmasinsertParmas')
        getApp()
          .globalData.request(
            "/map/insertMsyhQueryResult", insertParmas,
            "POST"
          )
          .then((rstObj) => {
            console.log(rstObj, 'rstObjrstObjrstObj')
            setTimeout(() => {
              this.setData({
                loading: false
              })
            }, 500);
          });
      });



  },
  deuce() {
    // wx.navigateTo({
    //   url: '../deuce/deuce'
    // })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options, 'optionsoptions')
    getApp()
      .globalData.request(
        "/map/getNewInfoByCorpKey", {
        corpKey: options.corpKey,
      },
        "POST"
      )
      .then((res) => {
        res.data.jkJbxxSfxxNew.corpLabelList = res.data.corpLabelList[0].labelList
        res.data.jkJbxxSfxxNew.totalscore = res.data.corpLabelList[0].totalscore
        res.data.jkJbxxSfxxNew.creditRate = res.data.corpLabelList[0].creditRate


        if (res.code == 200) {
          this.setData({
            corpKey: options.corpKey,

            Company: res.data,
            jkJbxxSfxx: res.data.jkJbxxSfxxNew,
          });

        }
      });

    this.setData({
      corpKey: options.corpKey,
      corpName: options.corpName,
    });
    this.getScore()

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() { },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() { },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() { },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() { },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() { },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() { },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() { },
});